package com.aegean.MonitorExamSYS.monitor.action;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExamSYS.monitor.business.MonitorBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.aegean.MonitorExaxSYS.model.MonitorValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("MonitorPhoto")
@Scope("prototype")
public class MonitorPhoto extends ActionSupport {
	InputStream monitor_Photo;
	String photoName;
	@Resource
	MonitorBusiness business;

	public String getPhotoName() {
		return photoName;
	}

	public void setPhotoName(String photoName) {
		this.photoName = photoName;
	}

	public String getPhotoType() {
		return photoType;
	}

	public void setPhotoType(String photoType) {
		this.photoType = photoType;
	}

	String photoType;

	public InputStream getDownload() {
		try {
			MonitorValue user = (MonitorValue) ServletActionContext
					.getRequest().getSession().getAttribute("MonitorLogin");
			monitor_Photo = business.showPhoto(user.getUser_Id())
					.getBinaryStream();
			photoName = user.getUser_Photo().getPhoto_Name();
			photoType = user.getUser_Photo().getPhoto_Type();
			return monitor_Photo;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

}
